package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "套餐相关接口")
@Slf4j
public class SetmealController {
@Autowired
    private SetmealService setmealService;

@GetMapping("/admin/setmeal/page")
    public Result page(SetmealPageQueryDTO setmealPageQueryDTO)
{
    log.info("分页查询");
  PageResult pageResult =  setmealService.pageQuery(setmealPageQueryDTO);
    return Result.success(pageResult);
}



@PostMapping("/admin/setmeal")
public Result save(@RequestBody SetmealDTO setmealDTO)
    {
    log.info("新增套餐");
    setmealService.save(setmealDTO);
    return Result.success();
    }



 @PostMapping("/admin/setmeal/status/{status}")
 public Result startOrStop(@PathVariable Integer status, Long id)
 {
     log.info("起售或停售套餐");
     setmealService.startOrStop(status,id);
     return Result.success();
 }

@DeleteMapping("/admin/setmeal")
   public Result delete(@RequestParam List<Long> ids)
   {
    log.info("删除套餐");
    setmealService.deleteBatch(ids);
    return Result.success();
   }

   @GetMapping("/admin/setmeal/{id}")
    public Result  getById(@PathVariable Long id)
   {
    log.info("查询套餐");
    SetmealVO setmealVO = setmealService.getById(id);
    return Result.success(setmealVO);
   }

   @PutMapping("/admin/setmeal")
    public Result update(@RequestBody SetmealDTO setmealDTO)
       {
    log.info("修改套餐");
    setmealService.update(setmealDTO);
    return Result.success();
       }

}
